def geocodes_find(address=str,city=str):
    key = '0a5fa5f35a83d6ad1863a8635db0bde4'
    url = 'https://restapi.amap.com/v3/geocode/geo?parameters'
    params = {
    'key':key,
    'address':address,
    'city':city,
    'output':'json'
    }
    response = requests.get(url,params=params)
    data = response.json()
    result = data["geocodes"][0]["location"]
    return(result)

def place_find(location=float):
    key = '0a5fa5f35a83d6ad1863a8635db0bde4'
    url = 'https://restapi.amap.com/v3/geocode/regeo?parameters'

    params = {
        'key':key,
        'location':location,
        'output':'json'
    }
    response = requests.get(url,params=params)
    place = response.json()
    place_find_result = place["regeocode"]["formatted_address"]
    return place_find_result

def district(keywords,subdistrict):
    url = 'https://restapi.amap.com/v3/config/district?parameters'
    key = '0a5fa5f35a83d6ad1863a8635db0bde4'

    params={
        'key':key,
        'keywords':keywords,
        'subdistrict':subdistrict,
        'page':'1',
        'offset':'20',
        'extensions':'base',
        'filter':'filter',
        'output':'json'
    }
    response = requests.get(url,params=params)
    data = response.json()
    return data

def walk(origin,destination):
    url = 'https://restapi.amap.com/v3/direction/walking?parameters'
    key = '0a5fa5f35a83d6ad1863a8635db0bde4'

    params = {
        'key':key,
        'origin':origin,
        'destination':destination,
        'output':'json'
    }

    response = requests.get(url,params=params)
    data = response.json()["route"]["paths"][0]["steps"]
    for i in range(0,len(data)):
        print(data[int(i)]["instruction"])

def POI_search(keyword):
    url = 'https://restapi.amap.com/v3/place/text?parameters'
    key = '0a5fa5f35a83d6ad1863a8635db0bde4'
    keyword = keyword

    params = {
        'key':key,
        'keywords':'keywords|美食',
        'city':'广州',
        'output':'json',
        'citylimit':'true'
    }

    response = requests.get(url,params=params)
    search_poi = response.json()
    search_poi
    df = pd.DataFrame(search_poi["pois"])
    return df

def IP(IP):
    url = 'https://restapi.amap.com/v3/ip?parameters'
    key = '0a5fa5f35a83d6ad1863a8635db0bde4'
    IP = IP # 百度搜索的IP地址

    params = {
        'key':key,
        'ip':IP,
        'output':'json',
    }

    response = requests.get(url,params=params)
    IP_place = response.json()["city"]
    return IP_place

def request_port(x,y):
    url = 'https://restapi.amap.com/v3/batch?key'

    headers = {
            'Content-Type':'application/json'
    }

    body = {
        "ops": [
            {
                "url": '/v3/place/around?offset=10&page=1&key=5d9ecde3c906860e39493987d1053573&output=json&radius=100000&types=080000&location='+ x
            },
            {
                "url": '/v3/place/around?offset=10&page=1&key=5d9ecde3c906860e39493987d1053573&output=json&radius=100000&types=080000&location='+ y
            }
        ]
    }

    params = {
        'key':'0a5fa5f35a83d6ad1863a8635db0bde4'
    }

    r = requests.post(url,params=params,headers=headers,json=body)
    data = r.json()
    return data

def staticmap(location,zoom,size=None,scale=1,markers=None,labels=None,paths=None,traffic=0,page=None,sig=None)->dict:
    url = 'https://restapi.amap.com/v3/staticmap?parameters'
    params={
        'key': '0a5fa5f35a83d6ad1863a8635db0bde4',
        'location':location,
        'zoom':zoom,
        'size':size,
        'scale':scale,
        'markers':markers,
        'labels':labels,
        'paths':paths,
        'traffic':traffic,
        'output':'json'
    }
    response = requests.get(url,params=params)
    data = Image.open(BytesIO(response.content))
    return data

def coordinate_change(locations):
    url = 'https://restapi.amap.com/v3/assistant/coordinate/convert?parameters'
    key = '0a5fa5f35a83d6ad1863a8635db0bde4'

    params = {
        'key':key,
        'locations':locations,
        'coordsys':'baidu',
        'output':'json',
    }

    response = requests.get(url,params=params)
    coordinate_change = response.json()
    coordinate_change_result = coordinate_change["locations"]
    return coordinate_change_result

def weather(city,extensions=all):
    url = 'https://restapi.amap.com/v3/weather/weatherInfo?parameters'
    key = '0a5fa5f35a83d6ad1863a8635db0bde4'

    params = {
        'key':key,
        'city':'440106',
        'extensions':'all',
        'output':'json',
    }

    response = requests.get(url,params=params)
    weather_find = response.json()
    return weather_find

def input_tips(keywords,city):
    url = 'https://restapi.amap.com/v3/assistant/inputtips?parameters'
    key = '0a5fa5f35a83d6ad1863a8635db0bde4'

    params = {
        'key':key,
        'keywords':keywords,
        'city':city,
        'output':'json',
    }

    response = requests.get(url,params=params)
    Tips = response.json()
    return Tips

def traffic_status(rectangle,extensions):
    url = 'https://restapi.amap.com/v3/traffic/status/rectangle?parameters'
    key = '0a5fa5f35a83d6ad1863a8635db0bde4'

    params = {
        'key':key,
        'level':'5',
        'rectangle':rectangle,
        'extensions':extensions,
        'output':'json',
    }

    response = requests.get(url,params=params)
    traffic_status = response.json()
    return traffic_status
